package main

import "fmt"

//遍历数组
func traversalArray() {
	city := [...]string{"北京", "深圳", "广州", "上海"}
	for i := 0; i < len(city); i++ {
		fmt.Printf("%v\n", city[i])
	}
	//for-range
	for i, i2 := range city {
		fmt.Println(i, i2)
	}
}

//遍历三维数组
func twoDimensionArray() {
	var a = [3][2][3]int{{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}, {{13, 14, 15}, {17, 22, 33}}}
	for _, i2 := range a {
		for _, i3 := range i2 {
			for _, i4 := range i3 {
				fmt.Println(i4)
			}
		}
	}
}

//找出数组中和为指定值的元素的下标
func findIndex() {
	var arr = []int{1, 3, 5, 7, 8}
	for i := 0; i < len(arr); i++ {
		for j := i + 1; j < len(arr); j++ {
			if arr[i]+arr[j] == 8 {
				fmt.Println(i, j)
			}
		}
	}
}
func main() {
	findIndex()
}

//闭包
